#{extends 'main.html' /}
#{set title:'Search Results' /}

#{set 'moreScripts'}
    <script src="@{'/public/javascripts/jquery.dataTables.min.js'}" type="text/javascript" charset="${_response_encoding}"></script>
    <script>
        $(document).ready( function() {
            oTable = $('.resultTable').dataTable();
        });
    </script>
#{/set}

#{navigation /}

<div class="content">
		<h1> Results: </h1>
	
	<div style="width: 80%; margin: auto">
		<table cellpadding="0" cellspacing="0" border="0" class="resultTable" id="userTable">
			<thead>
				<tr><th></th><th>Type</th></tr>
			</thead>
			<tbody>
				#{list items:courseResults, as:'course'}
					<tr><td><a href=@{Courses.show(course.id)}>${course.name}</a></td><td>Course</td></tr>
				#{/list}
				#{list items:lectureResults, as:'lecture'}
					<tr><td><a href=@{Lectures.show(lecture.id)}>${lecture.course.name}: ${lecture.name}</a></td><td>Lecture</td></tr>
				#{/list}
				#{list items:commentResults, as:'comment'}
					#{if comment.lecture}
						<tr><td><a href=@{Lectures.show(comment.lecture.id)}>${comment.lecture.course.name}: ${comment.lecture.name}</a></td><td>Comment</td></tr>
					#{/if}
					#{else}
						<tr><td><a href=@{Questions.show(comment.question.id)}>${comment.question.title}</a></td><td>Comment</td></tr>
					#{/else}
				#{/list}
				#{list items:userResults, as:'user'}
					<tr><td><a href=@{Users.show(user.id)}>#{if user.realname}${user.realname}#{/if}#{else}${user.name}#{/else}</a></td><td>User</td></tr>
				#{/list}
				#{list items:questionResults, as:'question'}
					#{if question.answered}
						<tr><td><a href=@{Answers.show(question.id)}> ${question.title}</a></td><td>Question</td></tr>
					#{/if}
					#{else}
						<tr><td><a href=@{Questions.show(question.id)}> ${question.title}</a></td><td>Question</td></tr>
					#{/else}
				#{/list}
				#{list items:answerResults, as:'answer'}
					<tr><td><a href=@{Answers.show(answer.question.id)}> ${answer.title} </a></td><td>Answer</td></tr>
				#{/list}
			</tbody>
		</table>
	</div>
</div>